package com.kwlt.smc.entity;

import java.util.ArrayList;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.codehaus.jackson.annotate.JsonIgnore;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;


import com.google.common.collect.Lists;
import com.kwlt.smc.util.ConUtils;

/**
 * 	企业表
 * 企业必须有对应的代理，跟代理是多对一的关系
 * 企业下拥有多名用户，和用户是一对多的关系
 * 企业拥有自己的权限
 * @author wangweiheng
 *
 */

@Entity
@Table(name="CP")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CP {
	private Long cpId;
	/**
	 * 企业名称
	 */
	private String cpName;
	
	private String cpCode;
	
	private String addr;
	
	private String email;
	
	private String postcode;
	
	private String cpType;
	
	private String status;
	
	private Date createDate;
	
	private String createBy;
	
	private Long sendCount;
	
	private Long succSendCount;
	
	private Long failSendCount;
	//企业持有用户数
	private int chUserCount;
	
	/**
	 * 格式化时间
	 */
	private String createDateStr;
	/**
	 * 权限编码列表
	 */
	private List<String> authList = Lists.newArrayList();
	/**
	 * 权限编码串
	 */
	private String authCodeString;
	
	/**
	 * 所属代理
	 */
	//private Dept dept;
	private Long deptId;
	
	
	private String cpNumbers;
	/**
	 * 用户列表
	 */
	//private List<User> userList = new ArrayList<User>();
	
	
	public CP(){
	}
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getCpId() {
		return cpId;
	}


	public void setCpId(Long cpId) {
		this.cpId = cpId;
	}


	public String getCpName() {
		return cpName;
	}


	public void setCpName(String cpName) {
		this.cpName = cpName;
	}


	public String getCpCode() {
		return cpCode;
	}


	public void setCpCode(String cpCode) {
		this.cpCode = cpCode;
	}


	public String getAddr() {
		return addr;
	}


	public void setAddr(String addr) {
		this.addr = addr;
	}


	public String getEmail() {
		return email;
	}


	public void setEmail(String email) {
		this.email = email;
	}


	public String getPostcode() {
		return postcode;
	}


	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}


	public String getCpType() {
		return cpType;
	}


	public void setCpType(String cpType) {
		this.cpType = cpType;
	}


	public String getStatus() {
		return status;
	}


	public void setStatus(String status) {
		this.status = status;
	}

	@Column(nullable=false)
	@Temporal(TemporalType.TIMESTAMP)
	public Date getCreateDate() {
		return createDate;
	}


	public void setCreateDate(Date createDate) {
		this.createDate = createDate;
		this.setCreateDateStr(ConUtils.formatDate(createDate,"yyyy-MM-dd"));
	}


	public String getCreateBy() {
		return createBy;
	}


	public void setCreateBy(String createBy) {
		this.createBy = createBy;
	}

	
	

	public String getCpNumbers() {
		return cpNumbers;
	}

	public void setCpNumbers(String cpNumbers) {
		this.cpNumbers = cpNumbers;
	}

	public Long getDeptId() {
		return deptId;
	}

	public void setDeptId(Long deptId) {
		this.deptId = deptId;
	}

	@ElementCollection
	@CollectionTable(name = "CP_AUTH", joinColumns = { @JoinColumn(name = "CP_ID") })
	@Column(name = "AUTH_CODE")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public List<String> getAuthList() {
		return authList;
	}

	public void setAuthList(List<String> authList) {
		this.authList = authList;
	}
	
	@Transient
	public String getAuthCodeString() {
		return authCodeString;
	}
	public void setAuthCodeString(String authCodeString) {
		this.authCodeString = authCodeString;
	}
	@Transient	
	public String getCreateDateStr() {
		return createDateStr;
	}

	public void setCreateDateStr(String createDateStr) {
		this.createDateStr = createDateStr;
	}

	@Transient
	public Long getSendCount() {
		return sendCount;
	}

	public void setSendCount(Long sendCount) {
		this.sendCount = sendCount;
	}

	@Transient
	public Long getSuccSendCount() {
		return succSendCount;
	}

	public void setSuccSendCount(Long succSendCount) {
		this.succSendCount = succSendCount;
	}
	
	@Transient
	public Long getFailSendCount() {
		return failSendCount;
	}

	public void setFailSendCount(Long failSendCount) {
		this.failSendCount = failSendCount;
	}

	@Transient
	public int getChUserCount() {
		return chUserCount;
	}

	public void setChUserCount(int chUserCount) {
		this.chUserCount = chUserCount;
	}
}
